/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CapadeDatos;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import modelo.beanlista;

/**
 *
 * @author jxtx
 */
public class daolistadoalumnos {
int codigo;
String literalcod;
     public static  ArrayList listado( String cod_carr,int cod_turno,JInternalFrame form ){
         ArrayList lista = new  ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
           String sql = "Call proc_listadoalumnos('"+cod_carr+"','"+cod_turno+"');";
            ResultSet rs =stm.executeQuery(sql);
           while (rs.next()){
                    beanlista y  = new  beanlista();
                   y.setCodalumno(rs.getString(1));
                   y.setNombre(rs.getString(2));
                   y.setApepat(rs.getString(3));
                   y.setApemat(rs.getString(4));
                   y.setDni(rs.getString(5));
                   y.setCarrera(rs.getString(6));
                   y.setTurno(rs.getString(7));
                   y.setCodalumno(rs.getString(8));
                   lista.add(y);
        }
     }catch(Exception e){System.out.print(e);
   }
    if(lista.isEmpty()){
        JOptionPane.showMessageDialog(form, "No hay nuevos alumnos registrados en esta Carrera/Turno");
    }
         return lista;


   }

     public void insertarmatricula(String cod,String obs){
        Boolean verdad = false;
        int k=0;
        try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Connection cn2 = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            Statement stm2 = cn2.createStatement();
            String sql ="select  Contador  from contador where Descripcion = 'matricula';";
            ResultSet rs =stm.executeQuery(sql);
            if(rs.wasNull()){
               verdad = false;              
            }
            else {
                verdad = true;
                 while (rs.next()){
                    codigo = rs.getInt(1);
                 }
               codigo = codigo + 1;
               String sql2 ="insert into matricula values "
                + "('"+cod+"', concat('0',"+codigo+"),'"+obs+"');";
                int rs2 =stm2.executeUpdate(sql2);
                if(rs2!=-1){
               verdad = false;
                JOptionPane.showMessageDialog(null,"INGRESADO");
                  Connection cn3 = ConexionBD.getInstance().getConnection();
                   Statement stm3 = cn3.createStatement();
                   String  sql3 ="update contador set contador = "+codigo+" where idContador = 3;";
                   stm3.executeUpdate(sql3);
                }
            else {
                verdad = true;
                JOptionPane.showMessageDialog(null,"NO INGRESADO");
                }
             }
    }catch(Exception e){System.out.print(e);
   }
   }

}
